import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

import common from './common'
//导入store对象
import store from '../store'

//动态加载组件
const router = new VueRouter({
    routes:[
       ...common
    ]
})
router.beforeEach((to,from,next)=>{
    if(to.path==='/login'){
        next()
        return
    }
    if(to.meta.reqLogin){
        let token = store.state.common.token
        if(token){
            next()
        }else{
            next('/login')
        }
    }
})
export default router